<include file="public@header"/>
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a href="{:url('Classroom/campus')}">校区管理</a></li>
        <li><a href="{:url('Classroom/add_campus')}">添加校区</a></li>
    </ul>
    <form class="well form-inline margin-top-20" method="post" action="{:url('classroom/find_campus')}" id="keyword">
        
        校区名称:
        <input type="text" id="name" class="form-control" data-provide="typeahead" autocomplete="off" name="name" style="width: 400px;" value="{$param['name']|default=''}" placeholder="校区名称...">
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
		<input type="submit" class="btn btn-primary" value="搜索"/>
        <input class="btn btn-danger" type="reset" value="重置"></input>
    </form>
	<if condition="isset($campus_info)">
	<form class="js-ajax-form" action="" method="post">
        <div class="table-actions">
            <input id="edit_campus" class="btn btn-primary" type="button" value="编辑校区"></input>
            <input id="article_campus" class="btn btn-primary" type="button" value="查看校区"></input>
            <input id="campus_classroom" class="btn btn-primary" type="button" value="教室管理"></input>
            <input id="add_classroom" class="btn btn-primary" type="button" value="添加教室"></input>
			<input id="campus_class" class="btn btn-primary" type="button" value="班级管理"></input>
            <input id="add_class" class="btn btn-primary" type="button" value="添加班级"></input>
            
            <!-- <button id="delete_campus" class="btn btn-danger js-ajax-submit" type="submit" style="float:right" -->
                    <!-- data-action="{:url('classroom/delete_campus')}" data-msg="您确定删除吗？">删除 -->
            <!-- </button> -->
        </div>
		
        <table class="table table-hover table-bordered table-list">
            <thead>
            <tr>
                <th width="15">
                    <label>
                        <input type="checkbox" class="js-check-all" data-direction="x" data-checklist="js-check-x">
                    </label>
                </th>
                <th>校区ID</th>
                <th>校区名称</th>
                <th>校区地址</th>
                <th>校区电话</th>
                <th>校区邮编</th>
            </tr>
            </thead>
            <foreach name="campus_info" item="vo">
                <tr name='{$vo.id}'>
                    <td>
                        <input type="checkbox" class="js-check" data-yid="js-check-y" data-xid="js-check-x" name="ids[]"
                               value="{$vo.id}" title="ID:{$vo.id}">
                    </td>
                    <td><b>{$vo.id}</b></td>
                    <td>{$vo.name}</td>
                    <td>{$vo.address|default='未知'}</td>
                    <td>{$vo.tel|default='未知'}</td>
                    <td>{$vo.zip|default='未知'}</td>
                </tr>
            </foreach>
        </table>
        <ul class="pagination">{$page|default=''}</ul>
	</form>
	</if>
</div>
<script src="__STATIC__/js/admin.js"></script>
<script>
	$(function(){
	var ids;
	function check_only(){
		var ids = [];
		$("input[name='ids[]']").each(function () {
			if ($(this).is(':checked')) {
				ids.push($(this).val());
			}
		});
		if (ids.length == 1){
			return ids;
		}
		else{
			return false;
		}
	}
	<!-- 校区教室 -->
		$("#campus_classroom").click(function(){
			if (ids = check_only()){
				var url = "{:url('Classroom/find_classroom','',false,true)}" + "/id/" + ids;
				window.location.href = url;
			}
			else{
				alert('请选择一个校区查看教室');
			}
		});
		<!-- 校区班级 -->
		$("#campus_class").click(function(){
			if (ids = check_only()){
				var url = "{:url('Class/find_class','',false,true)}" + "/id/" + ids;
				window.location.href = url;
			}
			else{
				alert('请选择一个校区查看班级');
			}
		});
		<!-- 添加教室 -->
		$("#add_classroom").click(function(){
			if (ids = check_only()){
				var url = "{:url('Classroom/add_classroom','',false,true)}" + "/id/" + ids;
				window.location.href = url;
			}
			else{
				alert('请选择一个校区添加教室');
			}
		});
		<!-- 添加班级 -->
		$("#add_class").click(function(){
			if (ids = check_only()){
				var url = "{:url('Class/add_class','',false,true)}" + "/id/" + ids;
				window.location.href = url;
			}
			else{
				alert('请选择一个校区添加班级');
			}
		});
	<!-- 编辑校区 -->
		$("#edit_campus").click(function(){
			if (ids = check_only()){
				var url = "{:url('Classroom/edit_campus','',false,true)}" + "/id/" + ids;
				<!-- alert(url); -->
				window.location.href = url;
			}
			else{
				alert('请选择一个校区进行编辑');
			}
		});
		<!-- 查看校区详情页 -->
		$("#article_campus").click(function(){
			if (ids = check_only()){
				var url = "{:url('portal/article/campus','',false,true)}" + "/id/" + ids;
				window.open(url);
			}
			else{
				alert('请选择一个要查看的校区！');
			}
		});
	});

	$(function(){
		$("tr[name]").click(function(){
			var id = $(this).attr("name");
			var is_check = $("input[value='"+id+"']").prop("checked");
			if(is_check){
				$("input[value='"+id+"']").prop("checked",false);
				$(this).prop("class",false);
			}
			else{
				$("input[value='"+id+"']").prop("checked",true);
				$(this).prop("class","success");
			}
		});
	});
</script>
</body>
</html>